local zhongshou = fk.CreateSkill{
    name = "wegame_2__zhongshou"
}
Fk:loadTranslationTable{
    ["wegame_2__zhongshou"] = "众守",
    [":wegame_2__zhongshou"] = "每回合限一次，你可以翻至背面以将你，上家与下家各一张牌当【闪】使用，然后三者同时抉择令你翻面或置底一张底牌。",
    ["#wegame_2__zhongshou-card"] = "众守：将你的一张牌当【闪】使用",
    ["#wegame_2__zhongshou-card2"] = "众守：将上家（%dest）的一张牌当【闪】使用",
    ["#wegame_2__zhongshou-card3"] = "众守：将下家（%dest）的一张牌当【闪】使用",
    ["#wegame_2__zhongshou-choose"] = "众守：令 %dest 翻面或置底一张底牌",
    ["#wegame_2__zhongshou1"] = "令 %dest 翻面",
    ["#wegame_2__zhongshou2"] = "置底一张底牌",
    ["$wegame_2__zhongshou"] = "底牌",
}

zhongshou:addEffect("viewas",{
    pattern = "jink",
    view_as = function (self, player, cards)
        if player:isNude() or player:getNextAlive():isNude() or player:getLastAlive():isNude() then return end
        local card = Fk:cloneCard("jink")
        card.skillName = self.name
        return card
    end,
    before_use = function (self, player, use)
        local room = player.room
        use.extra_data = use.extra_data or {}
        use.extra_data.wegame_2__zhongshou = {player,player:getLastAlive(),player:getNextAlive()}
        player:turnOver()
        for index, cp in ipairs({player,player:getLastAlive(),player:getNextAlive()}) do
            local card_data, visible_data = {}, {}
            if #cp:getCardIds("h") ~= 0 then
                local hands = {}
                for _, cid in ipairs(cp:getCardIds("h")) do
                    if not table.contains(use.card.subcards, cid) then
                        table.insertIfNeed(hands, cid)
                        if not player:cardVisible(cid) then
                            visible_data[tostring(cid)] = false
                        end
                    end
                end
                table.insert(card_data, {"$Hand", hands})
            end
            if #cp:getCardIds("e") ~= 0 then
                table.insert(card_data, {"$Equip", cp:getCardIds("e")})
            end
            local prompts = {"#wegame_2__zhongshou-card","#wegame_2__zhongshou-card2::"..cp.id,"#wegame_2__zhongshou-card3::"..cp.id}
            local card = room:askToChooseCard(player,{
                target = cp,
                flag = { card_data = card_data, visible_data = visible_data},
                skill_name = zhongshou.name,
                prompt = prompts[index],
            })
            use.card:addSubcard(card)
        end
    end,
    after_use = function (self, player, use)
        if use.extra_data and use.extra_data.wegame_2__zhongshou then
            local room = player.room
            local req = Request:new(use.extra_data.wegame_2__zhongshou, "AskForChoice")
            for _, cp in ipairs(use.extra_data.wegame_2__zhongshou) do
                req:setData(cp, { {"#wegame_2__zhongshou1::"..player.id,"#wegame_2__zhongshou2"}, {"#wegame_2__zhongshou1::"..player.id,"#wegame_2__zhongshou2"}, zhongshou.name, "#wegame_2__zhongshou-choose::"..player.id, false })
                req:setDefaultReply(cp, "#wegame_2__zhongshou1::"..player.id)
            end
            req.focus_text = zhongshou.name
            req.receive_decode = false
            local cards = {}
            for _, cp in ipairs(use.extra_data.wegame_2__zhongshou) do
                local result = req:getResult(cp)
                if result == "#wegame_2__zhongshou2" then
                    local card = room:askToChooseCard(cp, {
                        target = cp,
                        skill_name = zhongshou.name,
                        flag = { card_data = {{"$wegame_2__zhongshou",table.filter(use.card.subcards,function (element)
                            return not table.contains(cards, element)
                        end)}} },
                        prompt = "#wegame_2__zhongshou2",
                    })
                    table.insertIfNeed(cards, card)
                    room:moveCards {
                        ids = { card },
                        toArea = Card.DrawPile,
                        moveReason = fk.ReasonJustMove,
                        skillName = zhongshou.name,
                        proposer = player,
                        moveVisible = true,
                        drawPilePosition = -1
                    }
                else
                    player:turnOver()
                end
            end
        end
    end,
    enabled_at_play = function (self, player)
        return player:usedSkillTimes(zhongshou.name,Player.HistoryTurn) == 0 and player.faceup
    end,
    enabled_at_response = function (self, player, response)
        return not response and player:usedSkillTimes(zhongshou.name,Player.HistoryTurn) == 0 and player.faceup
    end,
})

return zhongshou